<?php $this->load->view('admin/Public/header'); ?>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-form layui-card-header layuiadmin-card-header-auto">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">地区名称</label>
					<div class="layui-input-inline">
						<input type="text" id="name" name="name" placeholder="请输入名称" autocomplete="off" class="layui-input">
					</div>
				</div>

				<button class="layui-btn" data-type="reload">搜索</button>
			</div>
		</div>

		<div class="layui-card-body">
			<script type="text/html" id="toolbarDemo">
				<div class="layui-btn-container">
					<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
					<button class="layui-btn layui-btn-sm" lay-event="history" id="back" style="display: none">上一级</button>
				</div>
			</script>
			<script type="text/html" id="barDemo2">
				<div class="layui-btn-container">
					{{#  if(d.level != 3){ }}
					<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="son">管理子地区</button>
					{{#  } else { }}

					{{#  } }}
				</div>
			</script>
			<table id="LAY-app-content-list" lay-filter="LAY-app-content-list" ></table>
			<!-- 记录层级-->
			<input type="hidden" id="a1" value=""/>
			<input type="hidden" id="a2" value=""/>
			<script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			</script>
		</div>
	</div>
</div>
  <script>
  layui.config({
    base: '/public/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'contlist', 'table'], function(){
    var table = layui.table
    ,form = layui.form;

      table.render({
          elem: '#LAY-app-content-list'
          , url: '/admin/Share/GetShareList'
          , title: 'GetShareList'
          ,toolbar: '#toolbarDemo'
          , totalRow: true
          , page: true
          ,cols: [[
              {field:'id', title:'ID',  fixed: 'left', unresize: true, sort: true}
              ,{field:'user_id', title:'用户'}
              ,{field:'commodity_id', title:'商品'}
              ,{field:'poster_id', title:'海报'}
              ,{field:'url', title:'地址'}
              ,{field:'created_at', title:'创建时间'}
              ,{field:'updated_at', title:'更新时间'}
              ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
          ]]
      });

      var $ = layui.$, active = {
          reload: function () {
              var name = $('#name').val();
              //执行重载
              table.reload('LAY-app-content-list', {
                  page: {
                      curr: 1 //重新从第 1 页开始
                  }
                  , where: {
                      name: name,
                  }
              });
          }
      };
      //监听工具条
      table.on('tool(LAY-app-content-list)', function(obj){
          var data = obj.data;
          if(obj.event === 'detail'){
              window.location.href = 'detail?id='+data.id;
              // layer.msg('ID：'+ data.id + ' 的查看操作');
          } else if(obj.event === 'del'){
              layer.confirm('真的删除行么', function(index){

              });
          } else if(obj.event === 'edit'){
              // alert('你确定要标记么');
              layer.alert('编辑行：<br>'+ JSON.stringify(data))
          }
      });

    $('.layui-card .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });


  });
  </script>
</body>
</html>
